Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports DotNetNuke

Namespace ModuleMasters.DNN.Modules.NCAAPoolStandings.Data

    Public Class SqlDataProvider

        Inherits DataProvider

#Region "Private Members"
		Private Const ProviderType As String = "data"
		Private _providerConfiguration As Framework.Providers.ProviderConfiguration = Framework.Providers.ProviderConfiguration.GetProviderConfiguration(ProviderType)
		Private _connectionString As String
		Private _providerPath As String
		Private _objectQualifier As String
		Private _databaseOwner As String
#End Region

#Region "Constructors"
		Public Sub New()

			' Read the configuration specific information for this provider
			Dim objProvider As Framework.Providers.Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Framework.Providers.Provider)

			' Read the attributes for this provider
			If objProvider.Attributes("connectionStringName") <> "" AndAlso _
			System.Configuration.ConfigurationSettings.AppSettings(objProvider.Attributes("connectionStringName")) <> "" Then
				_connectionString = System.Configuration.ConfigurationSettings.AppSettings(objProvider.Attributes("connectionStringName"))
			Else
				_connectionString = objProvider.Attributes("connectionString")
			End If

			_providerPath = objProvider.Attributes("providerPath")

			_objectQualifier = objProvider.Attributes("objectQualifier")
			If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
				_objectQualifier += "_"
			End If

			_databaseOwner = objProvider.Attributes("databaseOwner")
			If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
				_databaseOwner += "."
			End If

		End Sub
#End Region

#Region "Properties"
		Public ReadOnly Property ConnectionString() As String
			Get
				Return _connectionString
			End Get
		End Property

		Public ReadOnly Property ProviderPath() As String
			Get
				Return _providerPath
			End Get
		End Property

		Public ReadOnly Property ObjectQualifier() As String
			Get
				Return _objectQualifier
			End Get
		End Property

		Public ReadOnly Property DatabaseOwner() As String
			Get
				Return _databaseOwner
			End Get
		End Property
#End Region

#Region "General Public Methods"
		Private Function GetNull(ByVal Field As Object) As Object
			Return DotNetNuke.Common.Utilities.Null.GetNull(Field, DBNull.Value)
		End Function
#End Region

#Region "NCAAPoolStandings Methods"
	'---------------------------------------------------------------------
	' TODO Implement DAL methods.
    ' Use CodeSmith templates to generate this code
	'---------------------------------------------------------------------

        Public Overrides Function ListNCAAPoolStandings(ByVal PortalId As Integer, ByVal ModuleId As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "NCAAListPoolStandings", PortalId, ModuleId), IDataReader)
        End Function

        Public Overrides Function GetModuleList(ByVal PortalId As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "NCAAGetModuleList", PortalId), IDataReader)
        End Function

        'Public Overrides Function GetNCAAPoolStandingsByModules(ByVal ModuleId As Integer) As IDataReader
        '    Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "GetNCAAPoolStandingsByModules", ModuleId), IDataReader)
        'End Function

        'Public Overrides Function GetNCAAPoolStandings(ByVal ItemID As Integer, ByVal ModuleId As Integer) As IDataReader
        '    Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "GetNCAAPoolStandings", ItemID, ModuleId), IDataReader)
        'End Function

        'Public Overrides Function AddNCAAPoolStandings(ByVal ModuleId As Integer,  ByVal Param1 as String ) as Integer
        '    Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "AddNCAAPoolStandings", ModuleId, GetNull(Param1)), Integer)
        'End Function

        'Public Overrides Sub UpdateNCAAPoolStandings(ByVal ItemId As Integer, ByVal Param1 as String )
        '    SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "UpdateNCAAPoolStandings", ItemId, GetNull(Param1))
        'End Sub

        'Public Overrides Sub DeleteNCAAPoolStandings(ByVal ItemId As Integer)
        '    SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "DeleteNCAAPoolStandings", ItemId)
        'End Sub

#End Region

    End Class

End Namespace